<?php
class TaskAction extends  PublicAction
{//任务管理

	function index()
	{//任务管理首页
	//默认跳转至列表页
		redirect(__URL__.'/list_all/');
	}

	function list_all()
	{//查看任务列表
		$Dao = D("Task"); 
		$count = $Dao->count(); 
		import("ORG.Util.Page"); 
		if(!empty($_REQUEST["listRows"])) { 
			$listRows = $_REQUEST["listRows"]; 
			}else{ 
			$listRows = 20; 
		} 
		$p = new Page($count,$listRows); 
 
		$field = "*"; 
		$list = $Dao->findAll("",$field,"id desc",$p->firstRow.",".$p->listRows); 
		$page = $p->show(); 

		$list = get_userlist($list);

		$this->assign("list",$list); 
		$this->assign("page",$page); 
		$this->display("list"); 
	}


	function list_self()
	{//查看任务列表
		$Dao = D("Task"); 
		$count = $Dao->count(); 
		import("ORG.Util.Page"); 
		if(!empty($_REQUEST["listRows"])) { 
			$listRows = $_REQUEST["listRows"]; 
			}else{ 
			$listRows = 20; 
		} 
		$p = new Page($count,$listRows);
		$field = "*"; 
		$list = $Dao-> where('submitter='.$_SESSION['authId'])->field($field)->order("id desc")->limit($p->firstRow.','.$p->listRows)->findAll() ;
		$page = $p->show(); 

		$list = get_userlist($list);
		
		$this->assign("list",$list); 
		$this->assign("page",$page); 
		$this->display("list"); 
	}


    function edit($model='')
    {//默认编辑操作
        /** 通用编辑列表
		//取得编辑的Vo对象
        if(empty($model)) {
        	$model = $this->getModelClass();
        }
        if(!empty($model)) {
            $id = (int)$_REQUEST[$model->getPk()];
			$vo = $model->find($model->getPk()."='$id'");
			if(!$vo) {
				throw_exception(L('_SELECT_NOT_EXIST_'));
			}
			$this->cacheLockVersion($vo);
            $this->assign('vo',$vo);
            if($this->get('ajax')) {
                $this->ajaxReturn($vo);
            }
        }
        $this->display();
        return;
        */
        // 编辑页面 
		$Dao = D("Task"); 
		$vo = $Dao->find("id=".$_GET["id"]); 
		if($vo === false) 
		{ 
			$this->assign("jumpUrl",__URL__); 
			$this->error("Non-existed record"); 
		}
		$this->assign("vo",$vo); 
		$this->display(); 
        
    }

    function view()
    {//默认查看详细操作
        //$this->edit();
        //return;
        
        // 获取任务列表 
		$Dao = D("Task"); 
		$vo = $Dao->find("id=".$_GET["id"]); 
		if($vo === false) 
		{ 
			$this->assign("jumpUrl",__URL__); 
			$this->error("Non-existed record"); 
		}
		$this->assign("vo",$vo); 

		//获取回复内容
		$Daos = D("Taskflow"); 
		//$list = $Dao-> where("tid=".$_GET["id"])->order("id desc")->findAll();
		$voreply = $Daos-> where("tid=".$_GET["id"])->order("id desc")->findAll(); 
		if($voreply === false) 
		{ 
			$this->assign("jumpUrl",__URL__); 
			$this->error("Non-existed record"); 
		}
		$user_list = get_alluserlist();
		for ( $i = 0; $i < count($voreply); $i++ )
		{//查阅出可读人员的名单
			$voreply[$i]['submittername'] = $user_list[$voreply[$i]['submitter']];
		}//查阅相关名单结束----------------->
		$this->assign("voreply",$voreply);



		$this->display(); 
        
        
    }


	function reply()
	{//回复
		// 保存添加的数据
		$Dao = D("Taskflow"); 
		$vo = $Dao->create(); 
		if(false === $vo) { 
	 		$this->error($Dao->getError()); 
		} 

		$rs = $Dao->add(); 
		if($rs){ 
			$this->assign("jumpUrl",__URL__."/" ); 
			$this->success("添加数据成功!"); 
		}else{ 
			$this->error("添加数据失败"); 
		}
	}


/*
	function add() 
	{ 
		// 添加内容的页面 
		$this->display(); 
	} 

	function insert() 
	{ 
		// 保存添加的数据
		$Dao = D("Task"); 
		$vo = $Dao->create(); 
		if(false === $vo) { 
	 		$this->error($Dao->getError()); 
		} 

		$rs = $Dao->add(); 
		if($rs){ 
			$this->assign("jumpUrl",__URL__); 
			$this->success("添加数据成功!"); 
		}else{ 
			$this->error("添加数据失败"); 
		}
	}

	function edit() 
	{ 
		// 编辑页面 
		$Dao = D("Task"); 
		$vo = $Dao->find("id=".$_GET["id"]); 
		if($vo === false) 
		{ 
			$this->assign("jumpUrl",__URL__); 
			$this->error("Non-existed record"); 
		}
		$this->assign("vo",$vo); 
		$this->display(); 
	} 

	function update() 
	{ 
		// 保存编辑过的数据 
		$Dao = D("Task"); 
		
		$vo = $Dao->create("","edit");
		if(false === $vo) { 
	 		$this->error($Dao->getError()); 
		} 
		$rs = $Dao->save(); 
		if($rs){ 
			$this->assign("jumpUrl",__URL__); 
			$this->success("保存修改成功!"); 
		}else{ 
			$this->error("保存修改失败"); 
		} 
	}
*/
	function delete() 
	{// 根据id删除指定的记录
		$Dao = D("Task"); 
		$id = $_REQUEST["id"]; 
		if(isset($id)) { 
			$result = $Dao->getById($id); 
			if(!$result) { 
				$this->error("Non-existed record!"); 
			} 
			if($Dao->deleteById($id)){ 
				$this->assign("jumpUrl",__URL__); 
				$this->success("删除数据成功"); 
			}else { 
				$this->error("删除数据失败"); 
			}
		}else { 
			$this->error("非法操作"); 
		} 
	}
}
?>